import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: SegmentedHomePage());
  }
}

class SegmentedHomePage extends StatefulWidget {
  @override
  _SegmentedHomePageState createState() => _SegmentedHomePageState();
}

class _SegmentedHomePageState extends State<SegmentedHomePage> {
  int _selectIndex = 1;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('分段标签示例')),
      body: Column(
        children: [
          Container(
            padding: EdgeInsets.all(12),
            child: CupertinoSlidingSegmentedControl<int>(
              children: {1: Text('选项一'), 2: Text('选项二'), 3: Text('选项三')},
              //点击 回调
              onValueChanged: (int? index) {
                setState(() {
                  _selectIndex = index ?? 1;
                });
              },
              //当前选中的
              groupValue: _selectIndex,
              //选项卡的颜色
              thumbColor: Colors.blue.shade50,
              //背景颜色
              backgroundColor: Colors.red.shade50,
              //内边距
              padding: EdgeInsetsGeometry.only(
                left: 20,
                right: 20,
                top: 12,
                bottom: 12,
              ),
              proportionalWidth: true,
              //禁用的选项卡
              disabledChildren: {},
            ),
          ),
        ],
      ),
    );
  }
}
